// 创建birds.js
var express = require('express')
var patchApi = express.Router()// 创建一个路由实例

const data = [
    {
      "id": 590,
      "name": "ImageKnife",
      "briefDesc": "Axios是一个基于 promise 的网络请求库，可以运行 node.js 和浏览器中。本库基于Axios原库进行适配，使其可以运行在 OpenHarmony，并沿用其现有用法和特性。",
      "author": "opensource",
      "licence": "Apache 2.0 License",
      "gitUrl": "https://gitee.com/openharmony-tpc/Axios",
      "keyword": "OpenHarmony,http,request,promise,axios",
  },
  {
    "id": 591,
    "name": "zxing",
    "briefDesc": "zxing是一个解析/生成二维码的库，该项目是ts版本的zxing，在js-zxing的基础上补齐了与java-zxing库的差异的编码解码能力。",
    "author": "opensource",
    "licence": "MIT License",
    "gitUrl": "https://gitee.com/openharmony-tpc/zxing",
    "keyword": "zxing,OpenHarmony",
  }
  ]

  const userInfo = {
    name:'张三',
    age:25,
    sex:"男",
    province:"浙江",
    city:"杭州",
    country:"中国",
    area:"滨江",
    score:96,
    id:997,
    phone:"13714389438",
    pwd:"123456"
  }

// 中间件功能
patchApi.use(function timeLog (req, res, next) {
  console.log('Time: ', new Date().toLocaleString())
  next()
})
// 访问/patchApi
patchApi.patch('/', function (req, res) {
    console.log('zdy-----headers：------>'+JSON.stringify(req.headers))
    console.log('zdy-----path------>'+JSON.stringify(req.path))
    console.log('zdy-----baseUrl------>'+JSON.stringify(req.baseUrl))
    let requestPath = ''
    if(req.baseUrl != undefined && req.baseUrl != '' && req.baseUrl !=null && req.baseUrl.trim().length >0){
      requestPath= req.baseUrl
    }else if(req.path != undefined && req.path != '' && req.path !=null && req.path.trim().length >0){
      requestPath= req.path
    }
    let requestUrl = ''
    if('http' === req.protocol){
      requestUrl= 'http://'+req.hostname + requestPath
    }else{
      requestUrl= 'https://'+req.hostname + requestPath
    }
    console.log('zdy-----requestUrl------>'+requestUrl)
    let responseMsg = '请求：'+ requestUrl+'成功'
    res.json({
      header:req.headers,
      body:req.body,
      method:req.method,
      url:req.baseUrl,
      msg:responseMsg
    })
})




module.exports = patchApi